# download_leaflet.py
import os
import requests

# 设置目标目录
LEAFLET_DIR = "resources/leaflet"
os.makedirs(LEAFLET_DIR, exist_ok=True)

# 定义远程地址
LEAFLET_VERSION = "1.9.4"

LEAFLET_JS_URL = f"https://unpkg.com/leaflet@{LEAFLET_VERSION}/dist/leaflet.js"
LEAFLET_CSS_URL = f"https://unpkg.com/leaflet@{LEAFLET_VERSION}/dist/leaflet.css"

def download_file(url, filename):
    print(f"正在下载: {url}")
    response = requests.get(url)
    if response.status_code == 200:
        with open(filename, 'wb') as f:
            f.write(response.content)
        print(f"已保存: {filename}")
    else:
        print(f"下载失败: {url} (状态码 {response.status_code})")

def main():
    download_file(LEAFLET_JS_URL, os.path.join(LEAFLET_DIR, "leaflet.js"))
    download_file(LEAFLET_CSS_URL, os.path.join(LEAFLET_DIR, "leaflet.css"))

if __name__ == "__main__":
    main()
